#include <bits/stdc++.h>
using namespace std;
struct node{
    bool s=false;
    int z;
}a[11][20001];
int n,t;
int main (){
    freopen("color.in","r",stdin);
    freopen("color.out","w",stdout);
    cin>>t;
    for (int i=1;i<=t;i++){
        cin>>n;
        for (int j=1;j<=n;j++){
            cin>>a[t][j].z;
        }
    }
    for (int i=1;i<=t;i++){
        int ans=0;
        for(int l=1;l<=n;l++){
            for (int j=1;j<=n;j++){
                if (a[i][j].z==a[i][l].z){
                    ans+=a[i][j].z;
                }
            }
        }
        cout<<ans<<endl;









    }
    return 0;
}
